package code.chapter1.sort;

import java.lang.reflect.Array;

public class InsertionSort {
    private void sort(int[] array) {
        for (int j = 1; j < array.length; j++) {
            int key = array[j];
            int i = j - 1;
            while (i >= 0 && array[i] > key) {
                array[i + 1] = array[i];
                i--;
            }
            array[i + 1] = key;
        }
    }

    public static void main(String[] args) {
        int[] a = {5,2,4,1,6,3};
        new InsertionSort().sort(a);
        for (int s:a
             ) {
            System.out.print(s + " ");
        }
    }

}
